<?php

namespace App\Console\Commands;

use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Collection;
use App\Supports\Withdraw\WithdrawOverChecker;

class SyncUserCache extends Command
{
    protected $signature = 'cc:sync-user-cache';

    protected $description = "";

    public function handle()
    {
        User::query()
            //->whereHas('goldCharges')
            ->chunks(50, function (Collection $users) {

                if ($users->isEmpty()) return true;

                /**
                 * @var User $user
                 */
                foreach ($users as $user) {
                    $user->addToCache();
                    \Log::info("===== User: {$user->id} added to cache.");
                }

                return true;

            });
    }
}
